#include "Postopia.h"
#include "World.h"
#include "Tile.h"
#include "Item.h"
#include "Creature.h"

Postopia* Postopia::getSingleton()
{
	static Postopia* ms_postopia = 0;
	
	if(ms_postopia == 0)
	{
		ms_postopia = new Postopia();
	}

	return ms_postopia;
}

Postopia::Postopia()
{
	m_world = new World();
}

Postopia::~Postopia()
{
	//X == 11
	//Y == 7
}

void Postopia::onRun()
{	
	for(int x = 0; x < 11; ++x)
	{
		for(int y = 0; y < 7; ++y)
		{
			const Tile* tile = m_world->getTile(x, y, 0);
			if(!tile)
				continue;
				
			const ItemList items = tile->getItems();
			
			for(ItemList::const_iterator it = items.begin(); it != items.end(); ++it)
			{
				const Item* item = (*it);
				item->draw();
			}
			
			const CreatureList creatures = tile->getCreatures();
			
			for(CreatureList::const_iterator it = creatures.begin(); it != creatures.end(); ++it)
			{
				const Creature* creature = (*it);
				creature->draw();
			}
		}
	}
}